/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package podologia.beansDB;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 *
 * @author Hernan
 */
@Entity
@Table(name = "material")
@NamedQueries({@NamedQuery(name = "Material.findAll", query = "SELECT m FROM Material m"), @NamedQuery(name = "Material.findByIdMaterial", query = "SELECT m FROM Material m WHERE m.idMaterial = :idMaterial"), @NamedQuery(name = "Material.findByNombre", query = "SELECT m FROM Material m WHERE m.nombre = :nombre"), @NamedQuery(name = "Material.findByStockMinimo", query = "SELECT m FROM Material m WHERE m.stockMinimo = :stockMinimo"), @NamedQuery(name = "Material.findByStockActual", query = "SELECT m FROM Material m WHERE m.stockActual = :stockActual")})
public class Material implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id 
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Basic(optional = false)
    @Column(name = "idMaterial")
    private Integer idMaterial;
    @Column(name = "nombre")
    private String nombre;
    @Lob
    @Column(name = "descripcion")
    private String descripcion;
    @Column(name = "stockMinimo")
    private Integer stockMinimo;
    @Column(name = "stockActual")
    private Integer stockActual;
    @OneToMany(mappedBy = "idMaterial")
    private Collection<Detallepedido> detallepedidoCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idMaterial")
    private Collection<Materialesxproveedor> materialesxproveedorCollection;

    public Material() {
    }

    public Material(Integer idMaterial) {
        this.idMaterial = idMaterial;
    }

    public Integer getIdMaterial() {
        return idMaterial;
    }

    public void setIdMaterial(Integer idMaterial) {
        Integer oldIdMaterial = this.idMaterial;
        this.idMaterial = idMaterial;
        changeSupport.firePropertyChange("idMaterial", oldIdMaterial, idMaterial);
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        String oldNombre = this.nombre;
        this.nombre = nombre;
        changeSupport.firePropertyChange("nombre", oldNombre, nombre);
    }

    public String getDescripcion() {
        return descripcion;
    }

    public void setDescripcion(String descripcion) {
        String oldDescripcion = this.descripcion;
        this.descripcion = descripcion;
        changeSupport.firePropertyChange("descripcion", oldDescripcion, descripcion);
    }

    public Integer getStockMinimo() {
        return stockMinimo;
    }

    public void setStockMinimo(Integer stockMinimo) {
        Integer oldStockMinimo = this.stockMinimo;
        this.stockMinimo = stockMinimo;
        changeSupport.firePropertyChange("stockMinimo", oldStockMinimo, stockMinimo);
    }

    public Integer getStockActual() {
        return stockActual;
    }

    public void setStockActual(Integer stockActual) {
        Integer oldStockActual = this.stockActual;
        this.stockActual = stockActual;
        changeSupport.firePropertyChange("stockActual", oldStockActual, stockActual);
    }

    public Collection<Detallepedido> getDetallepedidoCollection() {
        return detallepedidoCollection;
    }

    public void setDetallepedidoCollection(Collection<Detallepedido> detallepedidoCollection) {
        this.detallepedidoCollection = detallepedidoCollection;
    }

    public Collection<Materialesxproveedor> getMaterialesxproveedorCollection() {
        return materialesxproveedorCollection;
    }

    public void setMaterialesxproveedorCollection(Collection<Materialesxproveedor> materialesxproveedorCollection) {
        this.materialesxproveedorCollection = materialesxproveedorCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idMaterial != null ? idMaterial.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Material)) {
            return false;
        }
        Material other = (Material) object;
        if ((this.idMaterial == null && other.idMaterial != null) || (this.idMaterial != null && !this.idMaterial.equals(other.idMaterial))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return nombre;
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }

}
